package com.lywz.biz.common.enums;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;


/**
 * @author Sunna
 * @date 2010-5-8 下午12:31:29
 */
public enum Country {
    guiyangone(1,"贵阳一区",City.guiyang),
    guiyangtwo(2,"贵阳二区",City.guiyang),
    guiyangthree(3,"贵阳三区",City.guiyang),
    guiyangfour(4,"贵阳四区",City.guiyang),
    guiyangfive(5,"贵阳五区",City.guiyang),
    guiyangsix(6,"贵阳六区",City.guiyang);
    
    public final Integer countryId;
    public final String name;
    public final City city;
    
    public int getCountryId() {
        return countryId;
    }
    
    public String getName() {
        return name;
    }
    
    public City getCity() {
        return city;
    }
    
    // 常量缓冲
    private static Map<Integer, Collection<Country>> countryListOfCityMap;
    private static Map<Integer, Country> countriesMap;
    private static Collection<Country> countryCollection;
    
    static{
        Collection<Country> countryListOfCity;
        countryListOfCityMap = new HashMap<Integer, Collection<Country>>();
        countriesMap = new HashMap<Integer, Country>();
        countryCollection = new ArrayList<Country>();
        for(Country c : Country.values()){
            countryListOfCity = null;
            countryListOfCity = countryListOfCityMap.get(c.getCity().getCityId());
            if (null == countryListOfCity){       
                countryListOfCity = new ArrayList<Country>();
                countryListOfCityMap.put(c.getCity().getCityId(), countryListOfCity);
            }
            countryListOfCityMap.get(c.getCity().getCityId()).add(c);
            countriesMap.put(c.getCountryId(), c);
            countryCollection.add(c);
        }
    }
    
    public static Collection<Country> valueOfByCityId(int cityId) {
        return countryListOfCityMap.get(cityId);
    }
    
    public static Country valueOfByCountryId(int countryId){
        return countriesMap.get(countryId);
    }
    
    public static Collection<Country> getCityCollection(){
        return countryCollection;
    }
      
    private Country(int countryId, String name, City city){
        this.countryId = countryId;
        this.name = name;
        this.city = city;
    }
    
}
